package org.itsolutions.javaBackup.gui.web.admin.view;

import org.itsolutions.javaBackup.gui.web.common.AStatefullView;
import org.itsolutions.javaBackup.gui.web.common.ApplicationDataHolder;
import org.itsolutions.javaBackup.gui.web.common.components.JBButton;
import org.itsolutions.javaBackup.gui.web.common.components.JBComboBox;
import org.itsolutions.javaBackup.gui.web.common.components.JBForm;
import org.itsolutions.javaBackup.gui.web.common.components.JBLabel;
import org.itsolutions.javaBackup.gui.web.common.components.JBTextField;
import org.itsolutions.javaBackup.gui.web.common.components.JBVerticalLayout;
import org.itsolutions.javaBackup.spi.backup.common.EBackupType;

import com.google.inject.Inject;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComponentContainer;

/**
 * 
 * @author Tomas Fecko
 */
public final class BackupView extends AStatefullView<BackupView> {

	@Inject JBVerticalLayout		mMainContainer;
	@Inject ApplicationDataHolder	mAppHolder;
	@Inject JBLabel					mFromLabel;
	@Inject JBLabel					mToLabel;
	@Inject JBForm					mForm;
	@Inject JBTextField				mFromTextField;
	@Inject JBTextField				mToTextField;	
    @Inject JBComboBox				mFromTypeCombo;
    @Inject JBComboBox				mToTypeCombo;
    @Inject JBButton				mBackup;
	
	@Override
	public ComponentContainer getMainContainer() {
		return mMainContainer;
	}

	@Override
	protected BackupView initOnce() {
		mMainContainer.setSizeFull();
		mMainContainer.setMargin(true);
		mMainContainer.setSpacing(true);
		
		mForm.setSizeUndefined();
		mForm.getLayout().addComponent(mFromLabel);
		mForm.getLayout().addComponent(mFromTypeCombo);
		mForm.getLayout().addComponent(mFromTextField);
		mForm.getLayout().addComponent(mToLabel);
		mForm.getLayout().addComponent(mToTypeCombo);
		mForm.getLayout().addComponent(mToTextField);
		mForm.getLayout().addComponent(mBackup);
		
		mMainContainer.addComponent(mForm);
		initText().initListeners().initModel();
		return this;
	}
	
	/**
	 * 
	 * @return
	 */
	private BackupView initText() {
		mForm.setCaption("BACKUP_HEADER.TTL");
		mForm.setDescription("BACKUP_FORM.DSC");
		mFromLabel.setCaption("FROM.LBL");
		mFromTypeCombo.setCaption("FROM_TYPE.LBL");
		mToTypeCombo.setCaption("TO_TYPE.LBL");
		mFromTextField.setCaption("");
		mToTextField.setCaption("");
		mToLabel.setCaption("TO.LBL");
		return this;
	}
	
	/**
	 * Inits listeners.
	 * @return this
	 */
	private BackupView initListeners() {
		mBackup.addListener(new ClickListener() {
			private static final long serialVersionUID = 3105013853831509576L;
			@Override
			public void buttonClick(ClickEvent pEvent) {
				
			}
		});
		return this;
	}
	
	/**
	 * 
	 * @return
	 */
	private BackupView initModel() {
		for (EBackupType type : EBackupType.values()) {
			mFromTypeCombo.addItem(type);
			mToTypeCombo.addItem(type);
		}
		return this;
	}
}






